package fr.uniscol.siecle.dao.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import fr.uniscol.siecle.model.Division;
import fr.uniscol.siecle.model.Eleve;
import fr.uniscol.siecle.model.Groupe;
import fr.uniscol.siecle.model.StructureEleve;

public class StructureEleveRowMapper implements RowMapper<StructureEleve> {

	@Override
	public StructureEleve mapRow(ResultSet rs, int rowNum) throws SQLException {
		
		Eleve eleve = new Eleve();
		eleve.setId(rs.getString("ELEVE_ID"));
		
		Division st = null;
		if(rs.getString("TYPE_STRUCTURE").equals("DI")){
			st = new Division();
		}else{
			st = new Groupe();
		}
		st.setCode(rs.getString("CODE_STRUCTURE"));
		
		StructureEleve ste = new StructureEleve();
		ste.setEleve(eleve);
		ste.setStructure(st);
		ste.setType_structure(rs.getString("TYPE_STRUCTURE"));
		
		return ste;
	}
}
